package com.mcc.web.controller.system;

import java.util.Date;
import java.util.List;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import com.mcc.common.utils.SecurityUtils;
import com.mcc.system.domain.SysNotice;
import com.mcc.system.service.ISysNoticeService;

/**
 * 公告 信息操作处理
 *
 * @author gxy
 */
@Api(tags = "通知公告")
@ApiSort(13)
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {

    @Autowired
    private ISysNoticeService noticeService;

    @ApiOperation("获取通知公告列表")
    @ApiOperationSupport(order = 1)
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<SysNotice>> list(SysNotice notice) {
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    @ApiOperation("获取通知公告列表(分页)")
    @ApiOperationSupport(order = 2)
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/page")
    public AjaxResult<TableDataInfo<SysNotice>> page(SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    @ApiOperation("根据通知公告编号获取详细信息")
    @ApiOperationSupport(order = 3)
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping("/get/{noticeId}")
    public AjaxResult<SysNotice> getInfo(@PathVariable Long noticeId) {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId));
    }

    @ApiOperation("新增通知公告")
    @ApiOperationSupport(order = 4)
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysNotice notice) {
        return toAjax(noticeService.insertNotice(notice));
    }

    @ApiOperation("修改通知公告")
    @ApiOperationSupport(order = 5)
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysNotice notice) {
        return toAjax(noticeService.updateNotice(notice));
    }

    @ApiOperation("删除通知公告")
    @ApiOperationSupport(order = 6)
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds) {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }
}
